package com.bestsoft.web.controller.flow;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestsoft.common.annotation.Log;
import com.bestsoft.common.core.controller.BaseController;
import com.bestsoft.common.core.domain.AjaxResult;
import com.bestsoft.common.enums.BusinessType;
import com.bestsoft.flow.domain.FlowUserSupply;
import com.bestsoft.flow.service.IFlowUserSupplyService;
import com.bestsoft.common.utils.poi.ExcelUtil;
import com.bestsoft.common.core.page.TableDataInfo;

/**
 * 用户和供应商关联Controller
 * 
 * @author wj
 * @date 2023-09-04
 */
@RestController
@RequestMapping("/flow/usersupply")
public class FlowUserSupplyController extends BaseController
{
    @Autowired
    private IFlowUserSupplyService flowUserSupplyService;

    /**
     * 查询用户和供应商关联列表
     */
    @PreAuthorize("@ss.hasPermi('flow:usersupply:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowUserSupply flowUserSupply)
    {
        startPage();
        List<FlowUserSupply> list = flowUserSupplyService.selectFlowUserSupplyList(flowUserSupply);
        return getDataTable(list);
    }

    /**
     * 导出用户和供应商关联列表
     */
    @PreAuthorize("@ss.hasPermi('flow:usersupply:export')")
    @Log(title = "用户和供应商关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowUserSupply flowUserSupply)
    {
        List<FlowUserSupply> list = flowUserSupplyService.selectFlowUserSupplyList(flowUserSupply);
        ExcelUtil<FlowUserSupply> util = new ExcelUtil<FlowUserSupply>(FlowUserSupply.class);
        util.exportExcel(response, list, "用户和供应商关联数据");
    }

    /**
     * 获取用户和供应商关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:usersupply:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(flowUserSupplyService.selectFlowUserSupplyByUserId(userId));
    }

    /**
     * 新增用户和供应商关联
     */
    @PreAuthorize("@ss.hasPermi('flow:usersupply:add')")
    @Log(title = "用户和供应商关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowUserSupply flowUserSupply)
    {
        return toAjax(flowUserSupplyService.insertFlowUserSupply(flowUserSupply));
    }

    /**
     * 修改用户和供应商关联
     */
    @PreAuthorize("@ss.hasPermi('flow:usersupply:edit')")
    @Log(title = "用户和供应商关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowUserSupply flowUserSupply)
    {
        return toAjax(flowUserSupplyService.updateFlowUserSupply(flowUserSupply));
    }

    /**
     * 删除用户和供应商关联
     */
    @PreAuthorize("@ss.hasPermi('flow:usersupply:remove')")
    @Log(title = "用户和供应商关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplycode}")
    public AjaxResult remove(@PathVariable String[] supplycode)
    {
        return toAjax(flowUserSupplyService.deleteFlowUserSupplyByUserIds(supplycode));
    }
}
